
var ns, toast,Dialog;
var app = new Vue({
    el: '#app',
    data: {
        form:{},
        ChangeType:1,//调整方式，1-增加，2-减少
        ChangeNum:'',
        pointMsg:'',
    },
    methods: {
        editType:function(type){
            var that=this;
            that.ChangeType=type;
            that.pointMsg='';
            that.ChangeNum='';
        },
        inputNum:function(){
            var that=this;
            that.pointMsg='';
        },
        onChangeNum:function(){
            var that=this;
            if(that.ChangeType==2&&Number(that.ChangeNum)>Number(that.form.Stock)){
                console.log(1111);
                that.pointMsg="减少数量不能大于当前剩余库存"
            }
        },
        do_save:function(){
            var that=this;
            if(that.ChangeType==2&&Number(that.ChangeNum)>Number(that.form.Stock)){
                api.toast({
                    msg: '请重新输入调整数量',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            if(!that.ChangeNum){
                api.toast({
                    msg: '请输入调整数量',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            var option={};
            option.ProductID=that.form.ID;
            option.ChangeType=that.ChangeType;
            option.ChangeNum=that.ChangeNum;
            option.action='changeproductstok';
            console.log(JSON.stringify(option));
            ns.post(option, function(succeed, data, err) {
                if(succeed){
                    that.pointMsg='';
                    api.toast({
                        msg: '保存成功',
                        duration: 2000,
                        location: 'bottom'
                    });
                    
                    api.sendEvent({
                        name: 'edit_fee'
                    });
                    api.sendEvent({
                        name: 'reloadlist'
                    });
                    setTimeout(function() {
                        api.closeWin();
                    }, 500);

                }else{
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });

        }
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.form = api.pageParam.item;

};
